package work4;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TankClient04 extends Frame{
    int x=50,y=50;
    public void paint(Graphics g){
        Color c=g.getColor();
        g.setColor(Color.RED);
        g.fillOval(x,y,30,30);
        g.setColor(c);
        y+=5;
    }
    public void launchFrame(){
        this.setLocation(300,50);
        this.setSize(800,600);
        this.setBackground(Color.green);
        this.setTitle("TankWar");
        addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
        });
        setResizable(false);
        setVisible(true);

        new Thread(new PaintThread()).start();
    }

    private class PaintThread implements Runnable{
        //内部类（可以方便的访问包装类的方法。不方便公开的，只为包装类服务的类应当定义为内部类）
        @Override
        public void run() {
            while (true){
                repaint();
                try{
                    Thread.sleep(100);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        TankClient04 tc=new TankClient04();
        tc.launchFrame();
    }
}
